/**
 * Created by 游永年 on 2019-02-24 15:15.
 * 那个listView好麻烦,自己写一个
 */

'use strict'
import React from 'react';
import styles from './MyListView.less';
import Visit from "../Visit";

const visitStyle = {
  // visibility: 'hidden',
  backgroundColor: 'red',
  width: '100%',
  marginTop: '-10rem',
  display: 'block',
  height: '50rem',
}

class MyListView extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      visit: <div></div>,
    };
  }

  componentDidMount() {
    const fuck = _ => setTimeout(_ => {
      if (!!document.all.mainContainer) {
        this.setState({
          visit: <Visit visitStyle={visitStyle}
                        onVisit={() => this.handleVisit()}
                        onLeave={() => this.handleLeave()}
                        containerElement={document.all.mainContainer}
          />
        })
      } else {
        fuck();
      }
    }, 300);
    fuck();
  }

  render() {
    const {dataSource = [], renderRow} = this.props;
    console.log(document.getElementById('mainWindow'));
    return (
      <div className={styles.wrap}>
        {dataSource.map((obj, index) => {
          return <div className={styles.item} key={'alilaji' + index + obj.id}>
            {renderRow(obj, index)}
          </div>
        })}
        {this.state.visit}
      </div>
    );
  }

  handleVisit = _ => {
    console.log('handleVisit');
  }

  handleLeave = _ => {
    console.log('handleLeave');
  }

}

export default MyListView;
